package ink.ykb.aoplog.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import ink.ykb.aoplog.config.CodeConstant;
import ink.ykb.aoplog.config.MessageUtil;
import ink.ykb.aoplog.config.ResponseMsg;
import ink.ykb.aoplog.config.log.AopLog;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/")
@Slf4j
public class TestController {
	
	@Autowired
	private RestTemplate restTemplate;
	@Autowired
	private MessageUtil messageUtil;
	
	@AopLog(name = "test1接口",ignoreParam = "n", ignoreResultData = false)
	@RequestMapping("/test1")
	public ResponseMsg<List<String>> test1(String t,String n) {
		int a = (int)(Math.random() * 2);
		if(a ==0) {
			throw new RuntimeException("假装抛了一个异常");
		}
		List<String> list = new ArrayList<>();
		list.add("12312");
		return new ResponseMsg<>(CodeConstant.SUCCESS_000000,messageUtil.getMessage(CodeConstant.SUCCESS_000000),list);
	}

	@RequestMapping("/test")
	public ResponseMsg<String> test(int xh) {
		for (int i = 0; i < xh; i++) {
			new Thread(() ->{
				String result = restTemplate.getForObject("http://127.0.0.1:8080/test1?t=4&n=rtrt", String.class);
//				log.info("\nresult：{}",result);
			}).start();
		}
		try {
			Thread.sleep(3*1000);
		} catch (InterruptedException e) {
		}
		
		return new ResponseMsg<>(CodeConstant.SUCCESS_000000,messageUtil.getMessage(CodeConstant.SUCCESS_000000),null);
	}
	
	
	
}
